package net.csdn.business.search.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.csdn.business.common.domain.PageDto;
import net.csdn.business.common.domain.query.IssuePageQuery;
import net.csdn.business.common.domain.query.IssueSearchQuery;
import net.csdn.business.common.domain.query.RepoSearchQuery;
import net.csdn.business.common.domain.query.discuss.DiscussSearchQuery;
import net.csdn.business.common.domain.vo.IssueItemVO;
import net.csdn.business.common.domain.vo.IssueSearchVO;
import net.csdn.business.common.domain.vo.RepoSearchVO;
import net.csdn.business.common.domain.vo.discuss.DiscussSearchVO;
import net.csdn.business.search.facade.SearchFacade;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @ClassName SearchController
 * @Description SearchController
 * @Author zhangyl
 * @Date 2024/4/23 11:50
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/search")
public class SearchController
{

    private final SearchFacade searchFacade;

    /**
     * 讨论搜索
     */
    @PostMapping("/discuss")
    public PageDto<DiscussSearchVO> discussSearch(@RequestBody @Validated DiscussSearchQuery query) throws Exception{
        return searchFacade.discussSearch(query) ;
    }

    /**
     * issue搜索
     */
    @PostMapping("/issue")
    public PageDto<IssueSearchVO> issueSearch(@RequestBody @Validated IssueSearchQuery query) throws Exception{
        return searchFacade.issueSearch(query) ;
    }


    /**
     * 仓库搜索
     */
    @PostMapping("/repo")
    public PageDto<RepoSearchVO> repoSearch(@RequestBody @Validated RepoSearchQuery query) throws Exception{
        return searchFacade.repoSearch(query) ;
    }


    /**
     * 根据仓库id搜索issue
     */
    @PostMapping("/issue/project")
    public PageDto<IssueItemVO> searchByProject(@RequestBody @Validated IssuePageQuery query) throws Exception{
        return searchFacade.searchByProject(query);
    }

}
